﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ZDSoft.UPMS.Model.SystemPart;
using ZDSoft.UPMS.Model.BusinessPart;
using ZDSoft.UPMS.Manager.SystemPart;
using ZDSoft.UPMS.Manager.BusinessPart;
using ZDSoft.UPMS.Component.BusinessPart;
using Castle.ActiveRecord;
using System.IO;



namespace ZDSoft.UPMS.Component.SystemPart
{
    public class SystemSettingComponent : ActiveRecordBase
    {
        IList<User> UserList;
        IList<Role> RoleList;
        IList<Organization> OrganizationList;
        IList<SystemFunction> SystenFunctionList;
        IList<Course> CourseList;
        IList<Term> TermList;
        IList<Score> ScroeList;
        IList<Situation> SituationList;
        IList<SituationType> SituationTypeList;
        IList<UserCourseSituation> UserCourseSituationList;
        IList<TeacherTeachingCourse> TeacherTeachingCourseList;

        RoleComponent roleComponent = new RoleComponent();
        SystemFunctionComponent systemFunctionComponent = new SystemFunctionComponent();
        UserComponent userComponent = new UserComponent();
        CourseComponent courseComponent = new CourseComponent();
        OrganizationComponent organizationComponent = new OrganizationComponent();
        //RuleComponent ruleManager = new RuleComponent();
        ScoreComponent scoreComponent = new ScoreComponent();
        SituationComponent situationComponent = new SituationComponent();
        SituationTypeComponent situationTypeComponent = new SituationTypeComponent();
        TermComponent termComponent = new TermComponent();
        UserCourseSituationComponent userCourseSituationComponent = new UserCourseSituationComponent();
        TeacherTeachingCourseComponent teacherTeachingCourseComponent = new TeacherTeachingCourseComponent();
        /// <summary>
        /// 初始化系统数据
        /// </summary>
        public void CreateData()
        {
            InitSysFunctions();
            InitRole();
            InitTerm();
            InitCourse();
            InitScroe();
            InitOrganization();
            InitUser();
            InitRule();
            InitSituationType();
            //InitSituation();
            InitTeacherTeachingCourse();
            CreateProc();
            DeleteFunction();
        }

        /// <summary>
        /// 机构OK
        /// </summary>
        private void InitOrganization()
        {
            OrganizationList = new List<Organization>()
            {
                new Organization(){ Name="软件技术系",IsActive=true},
                new Organization(){ Name="C#教研室",IsActive=true},
                new Organization(){ Name="JAVA教研室",IsActive=true},
                new Organization(){ Name="软件测试教研室",IsActive=true},
                new Organization(){Name="软件开发（C#）101班",IsActive=true},
                new Organization(){Name="软件开发（C#）121班",IsActive=true},
                new Organization(){ Name="软件开发（JAVA）班",IsActive=true},
                new Organization(){ Name="软件测试班级",IsActive=true}
            };

            OrganizationList[4].SubOrganization = OrganizationList[1];
            OrganizationList[5].SubOrganization = OrganizationList[1];

            OrganizationList[6].SubOrganization = OrganizationList[2];
            OrganizationList[7].SubOrganization = OrganizationList[3];

            OrganizationList[1].SubOrganization = OrganizationList[0];
            OrganizationList[2].SubOrganization = OrganizationList[0];
            OrganizationList[3].SubOrganization = OrganizationList[0];

            foreach (Organization p in OrganizationList)
            {
                organizationComponent.Create(p);

            }
        }


        /// <summary>
        /// 添加基础用户OK
        /// </summary>
        private void InitUser()
        {
            UserList = new List<User>()
             {
                 new User() { Account = "Teacher", UserNumber="110010", Password = "123456", Name = "教师",IsActive=true,IsReset=false },
                 new User() { Account = "ClassHead",UserNumber="1100101", Password = "123456", Name = "辅导员",IsActive=true,IsReset=false },
                 new User() { Account = "TeacherHead",UserNumber="110", Password = "123456", Name = "教研室主任",IsActive=true ,IsReset=false},
                 new User() { Account = "DepartmentHead",UserNumber="1101", Password = "123456", Name = "系主任",IsActive=true ,IsReset=false},
                 new User() { Account = "Admin", Password = "123456",UserNumber="11", Name = "系统管理员",IsActive=true ,IsReset=false},
                 new User() { Account = "Student", Password = "123456",UserNumber="110010100", Name = "小明",IsActive=true ,IsReset=false},
                 new User() { Account = "Loin", Password = "123456",UserNumber="110010101", Name = "小李",IsActive=true ,IsReset=false},
                  new User() { Account = "32324", Password = "123456",UserNumber="110010100", Name = "小ll",IsActive=true ,IsReset=false},
             };
            UserList[0].Roles = new List<Role>();//实例化UserList中第一个user类的role属性
            UserList[0].Roles.Add(RoleList[0]);//是第一个用户拥有“学生”角色
            UserList[1].Roles = new List<Role>();
            UserList[1].Roles.Add(RoleList[1]);
            UserList[2].Roles = new List<Role>();
            UserList[2].Roles.Add(RoleList[2]);
            UserList[3].Roles = new List<Role>();
            UserList[3].Roles.Add(RoleList[3]);
            UserList[4].Roles = new List<Role>();
            UserList[4].Roles.Add(RoleList[4]);
            UserList[5].Roles = new List<Role>();
            UserList[5].Roles.Add(RoleList[5]);
            UserList[6].Roles = new List<Role>();
            UserList[6].Roles.Add(RoleList[5]);
            UserList[7].Roles = new List<Role>();
            UserList[7].Roles.Add(RoleList[5]);


            //为学生添加成绩
            UserList[5].Scores = new List<Score>();
            UserList[5].Scores.Add(ScroeList[0]);
            UserList[5].Scores.Add(ScroeList[1]);
            UserList[5].Scores.Add(ScroeList[2]);

            UserList[6].Scores = new List<Score>();
            UserList[6].Scores.Add(ScroeList[3]);
            UserList[6].Scores.Add(ScroeList[4]);
            UserList[6].Scores.Add(ScroeList[5]);

            UserList[7].Scores = new List<Score>();
            UserList[7].Scores.Add(ScroeList[2]);
            UserList[7].Scores.Add(ScroeList[3]);
            UserList[7].Scores.Add(ScroeList[4]);


            //机构
            UserList[0].Organization = OrganizationList[1];
            UserList[1].Organization = OrganizationList[0];
            UserList[2].Organization = OrganizationList[2];
            UserList[3].Organization = OrganizationList[0];
            UserList[5].Organization = OrganizationList[4];
            UserList[6].Organization = OrganizationList[5];
            UserList[7].Organization = OrganizationList[4];

            foreach (User user in UserList)
            {
                user.Password = System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(user.Password, "md5");
                userComponent.Create(user);
            }
        }

        /// <summary>
        /// 角色OK
        /// </summary>
        private void InitRole()
        {
            RoleList = new List<Role>()
            {
                 new Role() { Name = "教师", IsActive = true },
                  new Role() {Name = "辅导员", IsActive = true },
                 new Role() { Name = "教研室主任", IsActive = true },
                 new Role() { Name = "系主任", IsActive = true },
                 new Role() { Name = "系统管理员", IsActive = true },
                 new Role() { Name = "学生", IsActive = true },
            };
            //教师
            RoleList[0].SystemFunctions = new List<SystemFunction>();
            RoleList[0].SystemFunctions.Add(SystenFunctionList[4]);
            RoleList[0].SystemFunctions.Add(SystenFunctionList[5]);
            RoleList[0].SystemFunctions.Add(SystenFunctionList[9]);
            RoleList[0].SystemFunctions.Add(SystenFunctionList[11]);
            RoleList[0].SystemFunctions.Add(SystenFunctionList[13]);
            RoleList[0].SystemFunctions.Add(SystenFunctionList[14]);
            RoleList[0].SystemFunctions.Add(SystenFunctionList[16]);
            RoleList[0].SystemFunctions.Add(SystenFunctionList[17]);
            RoleList[0].SystemFunctions.Add(SystenFunctionList[18]);
            RoleList[0].SystemFunctions.Add(SystenFunctionList[19]);
            RoleList[0].SystemFunctions.Add(SystenFunctionList[21]);
            RoleList[0].SystemFunctions.Add(SystenFunctionList[22]);

            //辅导员
            RoleList[0].SystemFunctions = new List<SystemFunction>();
            RoleList[0].SystemFunctions.Add(SystenFunctionList[4]);
            RoleList[0].SystemFunctions.Add(SystenFunctionList[5]);
            RoleList[0].SystemFunctions.Add(SystenFunctionList[9]);
            RoleList[0].SystemFunctions.Add(SystenFunctionList[11]);
            RoleList[0].SystemFunctions.Add(SystenFunctionList[12]);
            RoleList[0].SystemFunctions.Add(SystenFunctionList[13]);
            RoleList[0].SystemFunctions.Add(SystenFunctionList[14]);
            RoleList[0].SystemFunctions.Add(SystenFunctionList[16]);
            RoleList[0].SystemFunctions.Add(SystenFunctionList[17]);
            RoleList[0].SystemFunctions.Add(SystenFunctionList[18]);
            RoleList[0].SystemFunctions.Add(SystenFunctionList[19]);
            RoleList[0].SystemFunctions.Add(SystenFunctionList[21]);
            RoleList[0].SystemFunctions.Add(SystenFunctionList[22]);


            //教研室主任
            RoleList[2].SystemFunctions = new List<SystemFunction>();
            RoleList[2].SystemFunctions.Add(SystenFunctionList[4]);
            RoleList[2].SystemFunctions.Add(SystenFunctionList[5]);
            RoleList[2].SystemFunctions.Add(SystenFunctionList[6]);
            RoleList[2].SystemFunctions.Add(SystenFunctionList[10]);
            RoleList[2].SystemFunctions.Add(SystenFunctionList[11]);
            RoleList[2].SystemFunctions.Add(SystenFunctionList[12]);
            RoleList[2].SystemFunctions.Add(SystenFunctionList[13]);
            RoleList[2].SystemFunctions.Add(SystenFunctionList[14]);
            RoleList[2].SystemFunctions.Add(SystenFunctionList[15]);
            RoleList[2].SystemFunctions.Add(SystenFunctionList[16]);
            RoleList[2].SystemFunctions.Add(SystenFunctionList[17]);
            RoleList[2].SystemFunctions.Add(SystenFunctionList[18]);

            //系主任
            RoleList[3].SystemFunctions = new List<SystemFunction>();
            RoleList[3].SystemFunctions.Add(SystenFunctionList[0]);
            RoleList[3].SystemFunctions.Add(SystenFunctionList[1]);
            RoleList[3].SystemFunctions.Add(SystenFunctionList[2]);
            RoleList[3].SystemFunctions.Add(SystenFunctionList[3]);
            RoleList[3].SystemFunctions.Add(SystenFunctionList[4]);
            RoleList[3].SystemFunctions.Add(SystenFunctionList[5]);
            RoleList[3].SystemFunctions.Add(SystenFunctionList[6]);
            RoleList[3].SystemFunctions.Add(SystenFunctionList[7]);
            RoleList[3].SystemFunctions.Add(SystenFunctionList[8]);
            RoleList[3].SystemFunctions.Add(SystenFunctionList[9]);
            RoleList[3].SystemFunctions.Add(SystenFunctionList[10]);
            RoleList[3].SystemFunctions.Add(SystenFunctionList[11]);
            RoleList[3].SystemFunctions.Add(SystenFunctionList[12]);
            RoleList[3].SystemFunctions.Add(SystenFunctionList[13]);
            RoleList[3].SystemFunctions.Add(SystenFunctionList[14]);
            RoleList[3].SystemFunctions.Add(SystenFunctionList[15]);
            RoleList[3].SystemFunctions.Add(SystenFunctionList[16]);
            RoleList[3].SystemFunctions.Add(SystenFunctionList[17]);
            RoleList[3].SystemFunctions.Add(SystenFunctionList[18]);
            RoleList[3].SystemFunctions.Add(SystenFunctionList[19]);
            RoleList[3].SystemFunctions.Add(SystenFunctionList[20]);
            RoleList[3].SystemFunctions.Add(SystenFunctionList[21]);
            RoleList[3].SystemFunctions.Add(SystenFunctionList[22]);




            //系统管理员
            RoleList[4].SystemFunctions = new List<SystemFunction>();
            RoleList[4].SystemFunctions.Add(SystenFunctionList[0]);
            RoleList[4].SystemFunctions.Add(SystenFunctionList[1]);
            RoleList[4].SystemFunctions.Add(SystenFunctionList[2]);
            RoleList[4].SystemFunctions.Add(SystenFunctionList[3]);
            RoleList[4].SystemFunctions.Add(SystenFunctionList[16]);
            RoleList[4].SystemFunctions.Add(SystenFunctionList[17]);

            //学生
            RoleList[5].SystemFunctions = new List<SystemFunction>();
            RoleList[5].SystemFunctions.Add(SystenFunctionList[4]);
            RoleList[5].SystemFunctions.Add(SystenFunctionList[5]);
            RoleList[5].SystemFunctions.Add(SystenFunctionList[16]);
            RoleList[5].SystemFunctions.Add(SystenFunctionList[17]);
            RoleList[5].SystemFunctions.Add(SystenFunctionList[18]);
            RoleList[5].SystemFunctions.Add(SystenFunctionList[19]);
            RoleList[5].SystemFunctions.Add(SystenFunctionList[21]);
            RoleList[5].SystemFunctions.Add(SystenFunctionList[22]);

            foreach (Role role in RoleList)
            {
                ActiveRecordBase.Create(role);
            }

        }

        /// <summary>
        /// 功能OK
        /// </summary>
        private void InitSysFunctions()
        {
            SystenFunctionList = new List<SystemFunction>()
            {
                //0-3
                new SystemFunction() { Name = "系统管理", ClassName = "x", ControllerName = "x", ActionName = "x" },
                new SystemFunction() { Name = "用户管理", ClassName = "x", ControllerName ="User", ActionName ="Index"},
                new SystemFunction() { Name = "角色管理", ClassName = "x", ControllerName = "Role", ActionName = "Index" },
                new SystemFunction() { Name = "初始化密码", ClassName = "x", ControllerName = "User", ActionName = "ResetPassword" },
                
                //4-6
                new SystemFunction() { Name = "课程管理", ClassName = "x", ControllerName = "x", ActionName = "x" },
                new SystemFunction() { Name = "查看课程", ClassName = "x", ControllerName = "Course", ActionName = "Index" },
                new SystemFunction() { Name = "添加课程", ClassName = "x", ControllerName = "Course", ActionName = "Create" },
                
                //7-8
                new SystemFunction() { Name = "机构管理", ClassName = "x", ControllerName = "x", ActionName = "x" },          
                new SystemFunction() { Name = "添加机构", ClassName = "x", ControllerName = "Organization", ActionName = "Create" },

                //9-12
                new SystemFunction() { Name = "情况管理 ",ClassName= "x", ControllerName = "x", ActionName = "x" },
                new SystemFunction() { Name = "情况类型", ClassName = "x", ControllerName = "SituationType", ActionName = "Create" },
                new SystemFunction() { Name = "录入情况",ClassName= "x", ControllerName = "Situation", ActionName = "Create" },
                new SystemFunction() { Name = "修改学生情况",ClassName= "x", ControllerName = "Situation", ActionName = "Update" },

                //13-15
                new SystemFunction() { Name = "规则管理", ClassName = "x", ControllerName = "x", ActionName = "x" },
                new SystemFunction() { Name = "查看规则",ClassName= "x", ControllerName = "Rule", ActionName = "SituationRuleList" },
                new SystemFunction() { Name = "设置规则",ClassName= "x", ControllerName = "Rule", ActionName = "CreateRlueIndex" },

                //16-17
                new SystemFunction() { Name = "个人信息管理", ClassName = "x", ControllerName = "x", ActionName = "x" },
                new SystemFunction() { Name = "修改密码",ClassName= "x", ControllerName = "Account", ActionName = "ChangePassword" },

                //18-20
                new SystemFunction() { Name = "学期管理", ClassName = "x", ControllerName = "x", ActionName = "x" },
                new SystemFunction() { Name = "查看学期",ClassName= "x", ControllerName = "Term", ActionName = "Index" },
                new SystemFunction() { Name = "添加学期",ClassName= "x", ControllerName = "Term", ActionName = "Create" },

                //21-22
                new SystemFunction() { Name = "成绩管理", ClassName = "x", ControllerName = "x", ActionName = "x" },
                new SystemFunction() { Name = "查看成绩",ClassName= "x", ControllerName = "Score", ActionName = "Index" },
                
            };

            SystenFunctionList[1].Parent = SystenFunctionList[0];
            SystenFunctionList[2].Parent = SystenFunctionList[0];
            SystenFunctionList[3].Parent = SystenFunctionList[0];

            SystenFunctionList[5].Parent = SystenFunctionList[4];
            SystenFunctionList[6].Parent = SystenFunctionList[4];

            SystenFunctionList[8].Parent = SystenFunctionList[7];

            SystenFunctionList[10].Parent = SystenFunctionList[9];
            SystenFunctionList[11].Parent = SystenFunctionList[9];
            SystenFunctionList[12].Parent = SystenFunctionList[9];


            SystenFunctionList[14].Parent = SystenFunctionList[13];
            SystenFunctionList[15].Parent = SystenFunctionList[13];

            SystenFunctionList[17].Parent = SystenFunctionList[16];

            SystenFunctionList[19].Parent = SystenFunctionList[18];
            SystenFunctionList[20].Parent = SystenFunctionList[18];

            SystenFunctionList[22].Parent = SystenFunctionList[21];



            foreach (SystemFunction SysFunctions in SystenFunctionList)
            {
                systemFunctionComponent.Create(SysFunctions);
            }
        }

        /// <summary>
        /// 学期==
        /// </summary>
        private void InitTerm()
        {
            TermList = new List<Term>()
            {
                new Term(){Name="2011-2012年第一学期",StartTime=Convert.ToDateTime("2011-9"),StopTime=Convert.ToDateTime("2012-2")},
                new Term(){Name="2011-2012年第二学期",StartTime=Convert.ToDateTime("2012-3"),StopTime=Convert.ToDateTime("2012-7")},
                new Term(){Name="2012-2013年第一学期",StartTime=Convert.ToDateTime("2012-9"),StopTime=Convert.ToDateTime("2013-2")},
                new Term(){Name="2012-2013年第二学期",StartTime=Convert.ToDateTime("2013-3"),StopTime=Convert.ToDateTime("2013-7")},
                new Term(){Name="2013-2014年第一学期",StartTime=Convert.ToDateTime("2013-3"),StopTime=Convert.ToDateTime("2013-7")},
                new Term(){Name="2013-2014年第二学期",StartTime=Convert.ToDateTime("2013-9"),StopTime=Convert.ToDateTime("2014-2")},
            };

            foreach (Term term in TermList)
            {
                termComponent.Create(term);
            }
        }


        /// <summary>
        /// 成绩OK
        /// </summary>
        private void InitScroe()
        {
            ScroeList = new List<Score>()
            {
                new Score(){InitialScore=100.00f,FinalScore=100.00f,IsActive=true},
                new Score(){InitialScore=100.00f,FinalScore=100.00f,IsActive=true},
                new Score(){InitialScore=100.00f,FinalScore=100.00f,IsActive=true},
                new Score(){InitialScore=100.00f,FinalScore=100.00f,IsActive=true},
                new Score(){InitialScore=100.00f,FinalScore=100.00f,IsActive=true},
                new Score(){InitialScore=100.00f,FinalScore=100.00f,IsActive=true},
            };
            //成绩属于哪个学期？
            ScroeList[0].Term = TermList[0];
            ScroeList[1].Term = TermList[0];
            ScroeList[2].Term = TermList[1];
            ScroeList[3].Term = TermList[1];
            ScroeList[3].Term = TermList[2];
            ScroeList[4].Term = TermList[2];
            ScroeList[5].Term = TermList[3];

            ScroeList[0].Course = CourseList[0];
            ScroeList[1].Course = CourseList[1];
            ScroeList[2].Course = CourseList[2];
            ScroeList[3].Course = CourseList[3];


            foreach (Score score in ScroeList)
            {
                scoreComponent.Create(score);
            }
        }


        /// <summary>
        /// 课程OK==
        /// </summary>
        private void InitCourse()
        {
            CourseList = new List<Course>()
             {
                 new Course(){Name="C#程序设计",IsActive=true,lesson=45,WorkTiems=10,Remark="a"},
                 new Course(){Name="Java程序设计",IsActive=true,lesson=45,WorkTiems=10,Remark="asa"},
                 new Course(){Name="网页设计",IsActive=true,lesson=45,WorkTiems=10,Remark="aasd"},
                 new Course(){Name="软件工程",IsActive=true,lesson=45,WorkTiems=10,Remark="asw"},

             };
            CourseList[0].Term = TermList[3];
            CourseList[1].Term = TermList[3];
            CourseList[2].Term = TermList[3];
            CourseList[3].Term = TermList[3];


            foreach (Course course in CourseList)
            {
                courseComponent.Create(course);
            }
        }

        /// <summary>
        /// 情况类型
        /// </summary>
        private void InitSituationType()
        {
            SituationTypeList = new List<SituationType>()
            {
                new SituationType(){Name="作业情况"},
                new SituationType(){Name="纪律情况"},
                new SituationType(){Name="课堂表现"},

                new SituationType(){Name="上课睡觉"},
                new SituationType(){Name="玩手机"},
                new SituationType(){Name="玩游戏"},
                new SituationType(){Name="其他"},

                new SituationType(){Name="积极性"},
                new SituationType(){Name="优先完成练习"},
                new SituationType(){Name="其他"},

                new SituationType(){Name="课堂作业"},
                new SituationType(){Name="课后作业"},
                new SituationType(){Name="其他"},
            };
            SituationTypeList[7].Parent = SituationTypeList[1];
            SituationTypeList[8].Parent = SituationTypeList[1];
            SituationTypeList[9].Parent = SituationTypeList[1];

            SituationTypeList[3].Parent = SituationTypeList[2];
            SituationTypeList[4].Parent = SituationTypeList[2];
            SituationTypeList[5].Parent = SituationTypeList[2];
            SituationTypeList[6].Parent = SituationTypeList[2];

            SituationTypeList[10].Parent = SituationTypeList[0];
            SituationTypeList[11].Parent = SituationTypeList[0];
            SituationTypeList[12].Parent = SituationTypeList[0];



            foreach (SituationType t in SituationTypeList)
            {
                situationTypeComponent.Create(t);
            }
        }


        /// <summary>
        /// 情况
        /// </summary>
        private void InitSituation()
        {
            SituationList = new List<Situation>()
            {
                new Situation(){SelectCount=3,IsActive=true},
                new Situation(){SelectCount=4,IsActive=true},
                new Situation(){SelectCount=3,IsActive=true},
                new Situation(){SelectCount=2,IsActive=true},
                new Situation(){SelectCount=3,IsActive=true},
                new Situation(){SelectCount=2,IsActive=true},
            };
            SituationList[0].SituationType = SituationTypeList[7];
            SituationList[0].SituationType = SituationTypeList[8];
            SituationList[1].SituationType = SituationTypeList[9];
            SituationList[1].SituationType = SituationTypeList[3];
            SituationList[2].SituationType = SituationTypeList[4];
            SituationList[2].SituationType = SituationTypeList[5];
            SituationList[3].SituationType = SituationTypeList[6];
            SituationList[3].SituationType = SituationTypeList[10];
            SituationList[4].SituationType = SituationTypeList[11];
            SituationList[4].SituationType = SituationTypeList[12];


            foreach (Situation situation in SituationList)
            {
                situationComponent.Create(situation);
            }
        }


        private void InitUserCourseSituation()
        {
            UserCourseSituationList = new List<UserCourseSituation>()
            {
                new UserCourseSituation(){Date=Convert.ToDateTime("2013-3-4")},
                new UserCourseSituation(){Date=Convert.ToDateTime("2013-3-4")},
                new UserCourseSituation(){Date=Convert.ToDateTime("2013-3-4")},
            };
            UserCourseSituationList[0].User = UserList[5];
            UserCourseSituationList[0].Course = CourseList[0];

            UserCourseSituationList[1].User = UserList[5];
            UserCourseSituationList[1].Course = CourseList[1];

            UserCourseSituationList[2].User = UserList[7];
            UserCourseSituationList[2].Course = CourseList[2];

            UserCourseSituationList[0].Situations = new List<Situation>();
            UserCourseSituationList[0].Situations.Add(SituationList[3]);

            UserCourseSituationList[1].Situations = new List<Situation>();
            UserCourseSituationList[1].Situations.Add(SituationList[1]);

            UserCourseSituationList[2].Situations = new List<Situation>();
            UserCourseSituationList[2].Situations.Add(SituationList[0]);

            foreach (UserCourseSituation userCourseSituation in UserCourseSituationList)
            {
                userCourseSituationComponent.Create(userCourseSituation);
            }
        }
        /// <summary>
        /// 规则
        /// </summary>
        private void InitRule()
        {
        }

        /// <summary>
        /// 老师所教的课程
        /// </summary>
        private void InitTeacherTeachingCourse()
        {
            TeacherTeachingCourseList = new List<TeacherTeachingCourse>()
            {
                new TeacherTeachingCourse(){},
            };
            TeacherTeachingCourseList[0].Teacher = UserList[0];
            TeacherTeachingCourseList[0].Term = TermList[3];
            TeacherTeachingCourseList[0].Course = CourseList[2];
            TeacherTeachingCourseList[0].Classes = OrganizationList[4];
            foreach (TeacherTeachingCourse teacherTeachingCourse in TeacherTeachingCourseList)
            {
                teacherTeachingCourseComponent.Create(teacherTeachingCourse);
            }
        }

        /// <summary>
        /// 创建存储过程
        /// </summary>
        private void CreateProc()
        {
            bool Ishave = situationTypeComponent.IsHaveFunction("CalcScor");
            if (Ishave)
            {
                situationTypeComponent.Exec("drop proc dbo.CalcScor");
            }
            string str = "exec sp_executesql N'";
            str += " Create proc [dbo].[CalcScor](@ParentSituationType int,@ChildSituationType int,@Times int,@lesson int,@Score int) AS BEGIN ";
            IList<SituationType> situationTypes = situationTypeComponent.FindAll();
            IList<SituationType> FindSituationTypes = new List<SituationType>();
            foreach (SituationType situationType in situationTypes)
            {
                if (situationType.Parent == null)
                {
                    FindSituationTypes.Add(situationType);
                }
            }
            foreach (SituationType situationType in FindSituationTypes)
            {
                str += " IF(@ParentSituationType=" + situationType.ID + ") BEGIN UPDATE dbo.Score SET FinalScore = FinalScore - dbo.GetScor" + situationType.ID + "(@ParentSituationType,@ChildSituationType,@Times,@lesson) Where ID=@Score END";
            }
            str += " END' ";
            situationTypeComponent.Exec(str);
        }
        /// <summary>
        /// 清除数据库中的函数
        /// </summary>
        private void DeleteFunction()
        {
            bool Ishave;
            string str = "";
            IList<SituationType> situationTypes = situationTypeComponent.FindAll();
            IList<SituationType> FindSituationTypes = new List<SituationType>();
            foreach (SituationType situationType in situationTypes)
            {
                if (situationType.Parent == null)
                {
                    FindSituationTypes.Add(situationType);
                }
            }
            foreach (SituationType situationType in FindSituationTypes)
            {
                Ishave = situationTypeComponent.IsHaveFunction("GetScor" + situationType.ID);
                if (Ishave)
                {
                    str += "exec sp_executesql N'";
                    str += "drop FUNCTION dbo.GetScor" + situationType.ID + "'";
                }
            }
            if (str != "")
                situationTypeComponent.Exec(str);
        }
    }
}
